import _Checkbox from "choerodon-ui/lib/checkbox";
import _message from "choerodon-ui/lib/message";
import _InputNumber from "choerodon-ui/lib/input-number";
import _List from "choerodon-ui/lib/list";
import _Output from "choerodon-ui/pro/lib/output";
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import _Radio from "choerodon-ui/lib/radio";
import React, { PureComponent } from 'react';
import styles from "./index.less?modules";
var Group = _Radio.Group;

var Hour = /*#__PURE__*/function (_PureComponent) {
  _inherits(Hour, _PureComponent);

  var _super = _createSuper(Hour);

  function Hour(props) {
    var _this;

    _classCallCheck(this, Hour);

    _this = _super.call(this, props);

    _this.changeType = function (e) {
      var state = _objectSpread({}, _this.props.month);

      if (e.target.value === 'some') {
        state.some = ['1'];
      }

      if (e.target.value === 'period') {
        state.start = 1;
        state.end = 24;
      }

      if (e.target.value === 'beginInterval') {
        state.begin = 0;
        state.beginEvery = 1;
      }

      state.type = e.target.value;

      _this.props.onChange(state);
    };

    _this.formatHourOptions();

    return _this;
  }

  _createClass(Hour, [{
    key: "formatHourOptions",
    value: function formatHourOptions() {
      this.hourOptions = [];

      for (var x = 0; x < 24; x++) {
        this.hourOptions.push({
          label: x < 10 ? "0".concat(x) : x,
          value: "".concat(x)
        });
      }
    }
  }, {
    key: "changeParams",
    value: function changeParams(type, value) {
      var state = _objectSpread({}, this.props.hour);

      state[type] = value;
      this.props.onChange(state);
    }
  }, {
    key: "render",
    value: function render() {
      var _this2 = this;

      var _this$props$hour = this.props.hour,
          type = _this$props$hour.type,
          start = _this$props$hour.start,
          end = _this$props$hour.end,
          begin = _this$props$hour.begin,
          some = _this$props$hour.some,
          beginEvery = _this$props$hour.beginEvery;
      return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Group, {
        value: type,
        onChange: this.changeType
      }, /*#__PURE__*/React.createElement(_List, {
        size: "small",
        bordered: true,
        className: styles['cron-list']
      }, /*#__PURE__*/React.createElement(_List.Item, null, /*#__PURE__*/React.createElement(_Radio, {
        value: "*"
      }), /*#__PURE__*/React.createElement(_Output, {
        value: "\u6BCF\u5C0F\u65F6"
      })), /*#__PURE__*/React.createElement(_List.Item, {
        style: {
          marginBottom: 5
        }
      }, /*#__PURE__*/React.createElement(_Radio, {
        value: "period"
      }), /*#__PURE__*/React.createElement(_Output, {
        value: "\u5468\u671F"
      }), /*#__PURE__*/React.createElement(_Output, {
        value: "\u4ECE \xA0"
      }), /*#__PURE__*/React.createElement(_InputNumber, {
        min: 0,
        max: 24,
        defaultValue: 0,
        style: {
          width: 100
        },
        placeholder: "\u65F6",
        size: "small",
        value: start,
        onChange: function onChange(value) {
          _this2.changeParams('start', value);
        }
      }), /*#__PURE__*/React.createElement(_Output, {
        value: "\xA0\u5230\xA0"
      }), /*#__PURE__*/React.createElement(_InputNumber, {
        min: 0,
        max: 24,
        defaultValue: 24,
        style: {
          width: 100
        },
        placeholder: "\u65F6",
        value: end,
        size: "small",
        onChange: function onChange(value) {
          _this2.changeParams('end', value);
        }
      })), /*#__PURE__*/React.createElement(_List.Item, null, /*#__PURE__*/React.createElement(_Radio, {
        value: "beginInterval"
      }), /*#__PURE__*/React.createElement(_Output, {
        value: "\u4ECE\u7B2C\xA0"
      }), /*#__PURE__*/React.createElement(_InputNumber, {
        min: 0,
        max: 24,
        defaultValue: 0,
        style: {
          width: 100
        },
        placeholder: "\u65F6",
        size: "small",
        value: begin,
        onChange: function onChange(value) {
          _this2.changeParams('begin', value);
        }
      }), /*#__PURE__*/React.createElement(_Output, {
        value: "\xA0\u65F6\u5F00\u59CB\uFF0C\xA0\u6BCF\xA0"
      }), /*#__PURE__*/React.createElement(_InputNumber, {
        min: 0,
        max: 24,
        defaultValue: 1,
        style: {
          width: 100
        },
        placeholder: "\u5C0F\u65F6",
        size: "small",
        value: beginEvery,
        onChange: function onChange(value) {
          _this2.changeParams('beginEvery', value);
        }
      }), /*#__PURE__*/React.createElement(_Output, {
        value: "\xA0\u65F6\u6267\u884C\u4E00\u6B21"
      })), /*#__PURE__*/React.createElement(_List.Item, null, /*#__PURE__*/React.createElement(_Radio, {
        value: "some"
      }), /*#__PURE__*/React.createElement(_Output, {
        value: "\u6307\u5B9A\xA0",
        style: {
          whiteSpace: 'nowrap'
        }
      }), /*#__PURE__*/React.createElement(_Checkbox.Group, {
        value: some,
        onChange: function onChange(value) {
          if (value.length < 1) {
            return _message.warn('至少选择一项');
          }

          _this2.changeParams('some', value);
        },
        options: this.hourOptions
      })))));
    }
  }]);

  return Hour;
}(PureComponent);

export { Hour as default };